<?php include "../service/util/authenticateSession.php"; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
        <title>Sự kiện</title>
        <?php
        include "import.php";
        include "messages.properties.php";
        include "../service/eventService.php";
        ?>
    </head>
    <body>
        <?php include "header.php"; ?>
        <form id="form">
            <!-- Container -->
            <div id="container">
                <div class="shell"> 
                    <!-- Main -->
                    <div id="main">
                        <div class="cl">&nbsp;</div>
                        <!-- Content -->
                        <div id="content">
                            <?php
                            $message = "";
                            $class = "";
                            if (isset($_GET['msg']))
                                $msg = $_GET['msg'];

                            if (isset($msg)) {
                                if ($msg == "1") {
                                    $message = $messages["updateEventStatusOk"];
                                    $class = "msg msg-ok";
                                }
                            }
                            if ($message == "")
                                $class = 'msg msg-hidden';
                            ?>
                            <div class="<?php echo $class; ?>" id="msg">
                                <p><strong><?php echo $message; ?></strong></p>
                                <a href="#" onclick="hideMessage();" class="close">close</a>
                            </div>
                            <!-- Box -->
                            <div class="box">
                                <!-- Box Head -->
                                <div class="box-head">
                                    <h2 class="left">Danh sách sự kiện</h2> 
                                </div>
                                <!-- End Box Head -->	    
                                <!-- Table -->
                                <div class="table">
                                    <table width="100%" border="0" cellspacing="0" cellpadding="0">
                                        <tr>
                                            <th>STT</th>
                                            <th>Tên sự kiện (Tiếng Việt)</th>
                                            <th>Tên sự kiện (Tiếng Anh)</th>
                                            <th>Trạng Thái</th>
                                        </tr>
                                        <?php
                                        $result = findAllEvent();
                                        $count = 0;
                                        while ($row = ConnectionManager::getInstance()->fetch($result)) {
                                            $count++;
                                            ?>
                                            <tr>
                                                <td><?php echo $count; ?></td>
                                                <td><a href="event-detail.php?id=<?php echo $row["EVENT_ID"]; ?>"><?php echo $row["EVENT_TITLE_VN"]; ?></a></td>
                                                <td><?php echo $row["EVENT_TITLE_EN"]; ?></td>
                                                <td>
                                                    <select name="status<?php echo $row["EVENT_STATUS"]; ?>" onchange="submitForm('form', '../action/updateEventStatusAction.php?id=<?php echo $row["EVENT_ID"]; ?>', 'post');">
                                                        <option value="1" <?php if ($row["EVENT_STATUS"] == 1) echo "selected='selected'"; ?>>Đang chạy</option>
                                                        <option value="0" <?php if ($row["EVENT_STATUS"] == 0) echo "selected='selected'"; ?>>Tạm ngưng</option>
                                                    </select>
                                                </td>
                                            </tr>
                                        <?php
                                        }
                                        ?>
                                    </table>

                                </div>
                                <!-- Table -->
                                <div class="buttons">
                                    <input type="button" class="button" value="Thêm Sự Kiện" onClick="window.location='event-detail.php';" />
                                </div>
                            </div>
                            <!-- End Box -->
                        </div>
                        <!-- End Content -->
                        <div class="cl">&nbsp;</div>		
                    </div>
                    <!-- Main -->
                </div>
            </div>
            <!-- End Container -->
        </form>
<?php
include "footer.php";
ConnectionManager::getInstance()->closeConnection();
?>
    </body>
</html>